/// <reference path="../../node_modules/@types/underscore/index.d.ts" />
import {BrowserModule} from '@angular/platform-browser';
import {InjectionToken, NgModule} from '@angular/core';
import {registerLocaleData} from '@angular/common';
import {HTTP_INTERCEPTORS, HttpClient, HttpClientModule} from '@angular/common/http';
import zh from '@angular/common/locales/zh';
import {AppComponent} from './app.component';
import {LoginComponent} from './components/login/login.component';
import {RoutesModule} from './modules/routes/routes.module';
import {MainComponent} from './components/main/main.component';
import {NavbarComponent} from './components/main/navbar/navbar.component';
import {MenuComponent} from './components/main/menu/menu.component';
import {MenuItemComponent} from './components/main/menu/menu-item/menu-item.component';
import {ContentComponent} from './components/main/content/content.component';
import {
  NgToolsModule,
  serverConfigFactory,
  ServerConfigService,
  TokenInterceptorService, UnitPipe
} from '../ng-tools';
import {FormsModule, ReactiveFormsModule} from '@angular/forms';
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
import {AppMessageRegisterModule} from './modules/message-register/message-register.module';

import {ContextPipe} from './pipes/context-pipe';
import {MenuService} from './services/api/menu.service';
import {ServerTimeService} from './services/server-time.service';
import {CnTransPipe} from './pipes/cn-trans';

import {ThemeComponent} from './components/theme/theme.component';
import {ThemeService} from './services/theme.service';
import {CopyrightComponent} from './components/copyright/copyright.component';
import {ChannelManageComponent} from './components/main/content/channel-manage/channel-manage.component';
import {DvbConfigComponent} from './components/main/content/dvb-config/dvb-config.component';
import {DeviceManagerComponent} from './components/main/content/device-manager/device-manager.component';
import {DeviceCpuComponent} from './components/main/content/device-manager/echarts/device-cpu/device-cpu.component';
import {NetworkManageComponent} from './components/main/content/network-manage/network-manage.component';
import {DeviceMemoryUsageComponent} from './components/main/content/device-manager/echarts/device-memory-usage/device-memory-usage.component';
import {ChangeDvbConfigChannelComponent} from './components/main/content/dvb-config/change-dvb-config-channel/change-dvb-config-channel.component';
import {DvbChannelManagerComponent} from './components/main/content/dvb-channel-manager/dvb-channel-manager.component';
import {RegisterCodeComponent} from './components/main/content/register-code/register-code.component';
import {ChangePasswordComponent} from './components/main/content/user/change-password/change-password.component';
import {UserService} from './services/api/user.service';
import { ThirdToolsComponent } from './components/main/content/third-tools/third-tools.component';
import { DvbChannelInfoComponent } from './components/main/content/dvb-channel-manager/dvb-channel-info/dvb-channel-info.component';
import { DvbChannelRunningInfoComponent } from './components/main/content/dvb-channel-manager/dvb-channel-running-info/dvb-channel-running-info.component';

registerLocaleData(zh);

export const configFilePath = new InjectionToken('config file', {factory: () => 'config.json'});


const serverConfigProvider = {
  provide: ServerConfigService,
  useFactory: serverConfigFactory,
  deps: [HttpClient, configFilePath]
};


@NgModule({
  declarations: [
    AppComponent,
    LoginComponent,
    MainComponent,
    NavbarComponent,
    MenuComponent,
    MenuItemComponent,
    ContentComponent,
    ContextPipe,
    ChangePasswordComponent,
    CnTransPipe,
    ThemeComponent,
    CopyrightComponent,
    ChannelManageComponent,
    DvbConfigComponent,
    DeviceManagerComponent,
    DeviceCpuComponent,
    NetworkManageComponent,
    DeviceMemoryUsageComponent,
    ChangeDvbConfigChannelComponent,
    DvbChannelManagerComponent,
    RegisterCodeComponent,
    ThirdToolsComponent,
    DvbChannelInfoComponent,
    DvbChannelRunningInfoComponent,
  ],
  imports: [
    BrowserModule,
    RoutesModule,
    BrowserAnimationsModule,
    HttpClientModule,
    FormsModule,
    ReactiveFormsModule,
    AppMessageRegisterModule,
    NgToolsModule,
  ],
  providers: [
    ThemeService,
    ServerTimeService,
    HttpClient,
    serverConfigProvider,
    MenuService,
    UserService,
    {provide: HTTP_INTERCEPTORS, useClass: TokenInterceptorService, multi: true},
    ContextPipe,
    UnitPipe
  ],
  entryComponents: [
    ChangePasswordComponent,
    ChangePasswordComponent,
    ChangeDvbConfigChannelComponent,
    DvbChannelInfoComponent,
    DvbChannelRunningInfoComponent,
  ],
  bootstrap: [AppComponent]
})
export class AppModule {
}
